#include <iostream>
#include <unordered_set>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
using namespace std;

//a:0  b:1 c:2 d:3 e:4 f:5 g:6
int a[7];
int ret;
vector<char> edge[7];
unordered_set<string> has;
void dfs(int pos,string s)
{
	sort(s.begin(),s.end());
	if(!has.count(s) && s.size())
	{
		cout<<s<<endl;
		has.insert(s);
	}	
	for(auto& ch:edge[pos])
	{
		if(!a[ch-'a'])
		{
			a[ch-'a']=1;
			dfs(ch-'a',s+ch);
			a[ch-'a']=0;
		}
	}
}

int main()
{
	edge[0].push_back('f');
	edge[0].push_back('b');
	
	edge[1].push_back('a');
	edge[1].push_back('g');
	edge[1].push_back('c');
	
	edge[2].push_back('b');
	edge[2].push_back('g');
	edge[2].push_back('d');
	
	edge[3].push_back('c');
	edge[3].push_back('e');
	
	edge[4].push_back('f');
	edge[4].push_back('g');
	edge[4].push_back('d');
	
	edge[5].push_back('g');
	edge[5].push_back('a');
	edge[5].push_back('e');
	
	edge[6].push_back('f');
	edge[6].push_back('b');
	edge[6].push_back('e');
	edge[6].push_back('c');
	for(int i=0;i<7;i++)
	{
		a[i]=1;
		char c='a'+i;
		string s;
		s+=c;
		
		dfs(i,s);
		a[i]=0;
	}
	cout<<has.size();
	return 0;
}
